#include <php.h>
#include <wiringPiI2C.h>
#include "i2c_library.h"

//int wiringPiI2CSetup (int devId) ;
//int wiringPiI2CWrite (int fd, int data) ;
//int wiringPiI2CRead (int fd) ;
//int wiringPiI2CWriteReg8 (int fd, int reg, int data) ;
//int wiringPiI2CWriteReg16 (int fd, int reg, int data) ;
//int wiringPiI2CReadReg8 (int fd, int reg) ;
//int wiringPiI2CReadReg16 (int fd, int reg) ;

PHP_FUNCTION(wiringPiI2CSetup)
{
    long deviceId;

    ZEND_PARSE_PARAMETERS_START(1, 1)
        Z_PARAM_LONG(deviceId)
    ZEND_PARSE_PARAMETERS_END();

    long ret = wiringPiI2CSetup(deviceId);

    RETURN_LONG(ret);
}

//int wiringPiI2CRead (int fd) ;
PHP_FUNCTION(wiringPiI2CRead)
{
    long fd;
    ZEND_PARSE_PARAMETERS_START(1, 1)
        Z_PARAM_LONG(fd)
    ZEND_PARSE_PARAMETERS_END();

    long ret = wiringPiI2CRead(fd);

    RETURN_LONG(ret);
}

//int wiringPiI2CWrite (int fd, int data) ;
PHP_FUNCTION(wiringPiI2CWrite)
{
    long fd;
    long data;

    ZEND_PARSE_PARAMETERS_START(2, 2)
        Z_PARAM_LONG(fd)
        Z_PARAM_LONG(data)
    ZEND_PARSE_PARAMETERS_END();

    long ret = wiringPiI2CWrite(fd, data);
    RETURN_LONG(ret);
}

//int wiringPiI2CWriteReg8 (int fd, int reg, int data) ;
PHP_FUNCTION(wiringPiI2CWriteReg8)
{
    long fd;
    long reg;
    long data;

    ZEND_PARSE_PARAMETERS_START(3, 3)
        Z_PARAM_LONG(fd)
        Z_PARAM_LONG(reg)
        Z_PARAM_LONG(data)
    ZEND_PARSE_PARAMETERS_END();

    long ret = wiringPiI2CWriteReg8(fd, reg, data);
    RETURN_LONG(ret);
}
PHP_FUNCTION(wiringPiI2CWriteReg16)
{
    long fd;
    long reg;
    long data;

    ZEND_PARSE_PARAMETERS_START(3, 3)
        Z_PARAM_LONG(fd)
        Z_PARAM_LONG(reg)
        Z_PARAM_LONG(data)
    ZEND_PARSE_PARAMETERS_END();

    long ret = wiringPiI2CWriteReg16(fd, reg, data);
    RETURN_LONG(ret);

}

PHP_FUNCTION(wiringPiI2CReadReg8)
{
    long fd;
    long reg;

    ZEND_PARSE_PARAMETERS_START(2, 2)
        Z_PARAM_LONG(fd)
        Z_PARAM_LONG(reg)
    ZEND_PARSE_PARAMETERS_END();

    long ret = wirintPiI2CReadReg8(fd, reg);
    RETURN_LONG(ret);
}

PHP_FUNCTION(wiringPiI2CReadReg16)
{
    long fd;
    long reg;

    ZEND_PARSE_PARAMETERS_START(2, 2)
        Z_PARAM_LONG(fd)
        Z_PARAM_LONG(reg)
    ZEND_PARSE_PARAMETERS_END();

    long ret = wirintPiI2CReadReg16(fd, reg);
    RETURN_LONG(ret);
}

//end for i2c-library